<%@include file="/header.jsp"%>
<%@ page language="java" contentType="text/html" %>
<%@ page import="dataGateway.ItemTable" %>
<%@ page import="domainLogic.Item" %>
<%@ page import="java.util.Date" %>
<%
	Item newItem = (Item)session.getAttribute("newItem");
	if(newItem == null)
	{
		out.println(common.JspUtil.makeErrorMsg("Invalid access."));
		return;
	}
	else
	{
		session.setAttribute("newItem", null);
	}
	
	Date availabeEnddate = new Date(java.util.Calendar.getInstance().getTimeInMillis() + 10*60*1000);
	if(newItem.getEnddate().before(availabeEnddate))
	{
		out.println(common.JspUtil.makeErrorMsg("The end date and time should be after 10 minutes from now : "
	+ availabeEnddate));
		return;
	}
	
	if(newItem.getStartingprice() < 1)
		newItem.setStartingprice(1);
	
	if(ItemTable.getInstance().insertItem(newItem))
		out.println(common.JspUtil.makeErrorMsg("Item is created successfully.", common.JspUtil.URL_DEFAULT));
	else
		out.println(common.JspUtil.makeErrorMsg("Error to create the item!", common.JspUtil.URL_DEFAULT));
%>
<%@include file="/footer.jsp"%>